#include "pcb_fifo_queue.h"

/* resets the queue fifo */
void pcb_fifo_queue_reset(pcb_fifo_queue_t* fifo){
  fifo->count = 0;
  fifo->in = 0;
  fifo->out = 0;
}

/* puts the PCB pcb at the end of the queue. Returns 1 if success or 0 if the queue is full */
int32_t pcb_fifo_queue_put(pcb_fifo_queue_t* fifo, PCB* pcb){
  if(fifo->count >= MAX_QUEUE_LENGTH)
    return 0; //the queue is full
  //there is at least one free space
  fifo->queue[fifo->in] = pcb;
  fifo->in = (fifo->in+1) % MAX_QUEUE_LENGTH;
  fifo->count ++;
  return 1;
}

/* returns the head of the queue and removes it. Returns NULL if the queue is empty */
PCB* pcb_fifo_queue_get(pcb_fifo_queue_t* fifo){
  PCB* pcb;
  if(fifo->count <= 0)
    return NULL; //the queue is empty
  //there is at least one element in the queue
  pcb = fifo->queue[fifo->out];
  fifo->out = (fifo->out+1) % MAX_QUEUE_LENGTH;
  fifo->count --;
  return pcb;
}

/* removes the process pcb from the queue fifo. Returns 1 in case of success, 0 otherwise */
int32_t pcb_fifo_queue_remove(pcb_fifo_queue_t* fifo, PCB* pcb){
  return 1; //empty for now

}
